﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LevelTextOnNiceKeys : MonoBehaviour
{
    public Text numberText;
    public List<TextButton> tbList = new List<TextButton>();
    private string targetStr = "55566688833";
    private string curStr = string.Empty;
    public GameLevelItem gameLevelItem;
    // Start is called before the first frame update
    void Start()
    {
        InitTBList();
        numberText.text = curStr;
    }

    private void InitTBList()
    {
        int count = tbList.Count;
        for (int i = 0; i < count; i++)
        {
            int tempIndex = i;
            tbList[i].Init((tempIndex + 1).ToString(), () =>
            {
                TextButtonClick(tempIndex);
            });
        }
    }

    private void TextButtonClick(int index)
    {
        if (GameCtrl.Instance.curGameState != GameState.Play)
            return;
        curStr += tbList[index].text.text;
        numberText.text = curStr;
        if (curStr.Equals(targetStr))
            gameLevelItem.TriggerResult(true);

    }


}
